﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "CScoketImpl.h"

//1.初始化；
typedef void(*init_CSocketProtocol)(void** handle);
//2.发送接口；
typedef void(*send_CSocketProtocol)(void* handle, unsigned char* sendData, int sendLen);
//3.接收接口；
typedef void(*recv_CSocketProtocol)(void* handle, unsigned char* recvData, int* recvLen);
//4.关闭；
typedef void(*close_CSocketProtocol)(void* handle);

//5.业务代码；
void FrameWork(init_CSocketProtocol init, send_CSocketProtocol send,
	recv_CSocketProtocol recv, close_CSocketProtocol close)
{
	//6.初始化连接；
	void* handle = NULL;
	init(&handle);

	//7.发送数据；
	char sendBuf[] = "快点还钱！";
	int sendLen = strlen(sendBuf);
	send(handle, sendBuf, sendLen);

	//8.接收数据；
	char recvBuf[1024] = { 0 };
	int recvLen = 0;
	recv(handle, recvBuf, &recvLen);

	//10.输出数据；
	printf("11.接收到的数据recvBuf为：%s\n", recvBuf);//快点还钱！
	printf("12.接收到的数据长度recvLen为：%d\n", recvLen);//10

	//9.关闭连接；
	close(handle);
	handle = NULL;
}

void testInterface()
{
	FrameWork(init_CSocketImplProtocol, send_CSocketImplProtocol, recv_CSocketImplProtocol, close_CSocketImplProtocol);
}

//main220：面向接口编程
int main220()
{
	testInterface();

	system("pause");
	return EXIT_SUCCESS;
}